package com.yc.homepage.controller;


import com.alibaba.fastjson.JSON;
import com.yc.homepage.CourseInfo;
import com.yc.homepage.CourseInfosRequest;
import com.yc.homepage.service.ICourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <h1>课程对外服务接口</h1>
 * @author yc112
 */

@Slf4j
@RestController
public class HomepageCourseController {

    /**课程服务接口**/
    private final ICourseService courseService;


    public HomepageCourseController (ICourseService courseService) {
        this.courseService = courseService;
    }

    /**
     *  这里getMapping 要加上资源文件application.yml的 /homepage-course
     * @param id
     * @return
     */
    @GetMapping("/get/course")
    public CourseInfo getCourseInfo(Long id) {
        log.info("<homepage-course>: get course -> {}", id);
        return courseService.getCourseInfo(id);
    }

    @PostMapping("/get/courses")
    public List<CourseInfo> getCourseInfos(
            @RequestBody CourseInfosRequest request) {
        log.info("<homepage-course>: get courses -> {}", JSON.toJSONString(request));
        return courseService.getCourseInfos(request);
    }
}
